package main

import (
	"fmt"
	"io/ioutil"
	"os"
	"strings"
)

func Find(slice []string, val string) (bool) {
	for _, item := range slice {
		if item == val {
			return true
		}
	}
	return false
}

func GetAllFile(pathname string) error {
	rd, err := ioutil.ReadDir(pathname)
	dirNameList := make([]string,0)
	for _, fi := range rd {
		if fi.IsDir() {
			dirNameList = append(dirNameList, fi.Name())
		}
	}
	for _, fi := range rd {
		if fi.IsDir() {
			if find := strings.Contains(fi.Name(), "@"); find {
				splitname := strings.Split(fi.Name(), "@")[0]
				if Find(dirNameList, splitname) || splitname == ""{
					continue
				}
				oldpath := pathname+"\\"+fi.Name()
				newpath := pathname+"\\"+splitname
				os.Rename(oldpath, newpath)
				fmt.Printf("%s rename : %s\n",fi.Name(), splitname)
				dirNameList = append(dirNameList, splitname)
				//fmt.Println(oldpath, "+", newpath)

				//
			}
			GetAllFile(pathname+ "\\" + fi.Name())
		} else {
			//fmt.Println(fi.Name())
		}
	}
	return err
}

func main(){

	var path string = string("C:\\Users\\C\\Desktop\\gitCode\\training\\src\\vendor")
	GetAllFile(path)
	//os.Rename("C:\\Users\\C\\Desktop\\test", "C:\\Users\\C\\Desktop\\test01")
}